import 'package:animal/constant/font.dart';
import 'package:animal/model/models.dart';
import 'package:animal/socket/type_model.dart';
import 'package:animal/ui/friend/model/friend_model.dart';
import 'package:animal/ui/friend/page/friend_info_page.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/HeaderWidget.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

import 'LogUtil.dart';

class Utils {
  static String getImgPath(String name, {String format: 'png'}) {
    return 'images/$name.$format';
  }

  static void showSnackBar(BuildContext context, String msg) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(msg),
        duration: const Duration(seconds: 2),
      ),
    );
  }

  static Widget getSusItem(BuildContext context, String tag, {double susHeight = 40}) {
    if (tag == '★') {
      tag = '★ 热门城市';
    }
    return Container(
      height: susHeight,
      width: MediaQuery.of(context).size.width,
      padding: const EdgeInsets.only(left: 16.0),
      color: const Color(0xFFF3F4F5),
      alignment: Alignment.centerLeft,
      child: Text(
        tag,
        softWrap: false,
        style: const TextStyle(
          fontSize: 14.0,
          color: Color(0xFF666666),
        ),
      ),
    );
  }

  static Widget getWeChatListItem(
    BuildContext context,
    FriendModel model, {
    double susHeight = 40,
    Color? defHeaderBgColor,
  }) {
    return getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor);
//    return Column(
//      mainAxisSize: MainAxisSize.min,
//      children: <Widget>[
//        Offstage(
//          offstage: !(model.isShowSuspension == true),
//          child: getSusItem(context, model.getSuspensionTag(),
//              susHeight: susHeight),
//        ),
//        getWeChatItem(context, model, defHeaderBgColor: defHeaderBgColor),
//      ],
//    );
  }

  static Widget getWeChatItem(
    BuildContext context,
    FriendModel model, {
    Color? defHeaderBgColor,
  }) {
    DecorationImage? image;
    if (model.friendHead != null && model.friendHead!.isNotEmpty) {
      image = DecorationImage(
        image: CachedNetworkImageProvider("${model.friendHead}"),
        fit: BoxFit.contain,
      );
    }
    return Container(
      color: Colors.white,
      child: Column(
        children: [
          ListTile(
            leading: Header.defaultHead(imageUrl: model.friendHead, width: 45, height: 45, radius: 5),
            title: Text(
              model.friendNickName!,
              style: KFontConstant.myTextStyle(size: 14),
            ),
            onTap: () {
              // LogUtil.e("onItemClick : $model");
              Get.to(FriendInfoPage(
                userModel: UserModel(
                  name: model.friendName,
                  nickName: model.friendNickName,
                  head: model.friendHead,
                  id: model.friendUserId.toString(),
                  account: model.account,
                  riskContext: model.riskContext,
                  addType: model.addType,
                  isFriend: true,
                  friendAddType: model.friendApplyId.toString(),
                ),
              ));
            },
          ),
          Container(
            width: double.infinity,
            margin: EdgeInsets.only(left: ScreenUtil().L(60)),
            child: Divider(
              height: ScreenUtil().L(0.5),
              indent: 10.0,
            ),
          )
        ],
      ),
    );
  }

  static void focus() {
    FocusNode userFocusNode = FocusNode();
    userFocusNode.unfocus();
  }
}
